﻿using AutoMapper;
using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command;

namespace U.B.WriteApi.CommandHander
{
    public class UpdLeaveCommandHander : IRequestHandler<UpdLeaveCommand, ApiResult<string>>
    {
        private readonly IRepistory<LeaveApp> leaveRep;
        private readonly IMapper mapper;
         public UpdLeaveCommandHander(IRepistory<LeaveApp> leaveRep, IMapper mapper)
        {
                this.leaveRep = leaveRep;
                this.mapper = mapper;   
        }
        public Task<ApiResult<string>> Handle(UpdLeaveCommand request, CancellationToken cancellationToken)
        {
            ApiResult<string> result = new ApiResult<string>();

            var m = mapper.Map<LeaveApp>(request);
            var a = leaveRep.UpdateAsync(m).Result;
            if (a > 0)
            {
                result. code = Renum.修改成功;
                result.Message = "修改成功";
                result.Data = "修改成功";

            }
            else
            {
                result.code = Renum.修改失败;
                result.Message = "修改失败";
                result.Data = "修改失败";

            }

            return Task.FromResult(result);

        }
    }
}
